<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-商品详情</title>
	<link rel="stylesheet" type="text/css" href="${path}/static/front/css/reset.css">
	<link rel="stylesheet" type="text/css" href="${path}/static/front/css/main.css">

</head>
<body>
	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜!</div>
			<div class="fr">
				<div class="login_info fl">
					欢迎您：<em>张 山</em>
				</div>
				<div class="login_btn fl">
					<a href="">欢迎：${user.username}</a>
					<span>|</span>
					<a href="${path}/register.shtml">注册</a>
				</div>
				<div class="user_link fl">
					<span>|</span>
					<a href="${path}/user_center_info.shtml">用户中心</a>
					<span>|</span>
					<a href="${path}/cart.shtml">我的购物车</a>
					<span>|</span>
					<a href="${path}/user_center_order.shtml">我的订单</a>
					<span>|</span>
					<a href="${path}/product/getLoginPage.action">后台管理</a>
				</div>
			</div>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<a href="index.html" class="logo fl"><img src="${path}/static/front/images/logo.png"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>
		<div class="guest_cart fr">
			<a href="cart.html" class="cart_name fl">我的购物车</a>
			<div class="goods_count fl" id="show_count">1</div>
		</div>
	</div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="#" class="fruit">动态产品</a></li>
					<li><a href="#" class="seafood">海鲜水产</a></li>
					<li><a href="#" class="meet">猪牛羊肉</a></li>
					<li><a href="#" class="egg">禽类蛋品</a></li>
					<li><a href="#" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="#" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">家用电器</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl">
			<img style="width: 350px;height: 350px;" src="${product.mainImageFullUrl}">
		</div>

		<div class="goods_detail_list fr">
			<h3>${product.name}</h3>
			<p>${product.subtitle}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>${product.price}</em></span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input id="num" type="text" class="num_show fl" value="1">
					<a onclick="" href="javascript:;" class="add fr">+</a>
					<a onclick="" href="javascript:;" class="minus fr">-</a>	
				</div> 
			</div>
			<div class="total">总价：<em>${product.price}元</em></div>
			<div class="operate_btn">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart" id="add_cart" onclick="insertProductToCart()">加入购物车</a>				
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd>${product.detail}</dd>
				</dl>
			</div>

		</div>
	</div>

	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	<div class="add_jump"></div>

	<div id="loginForm" class="login_form fr" style="display:none">
		<div class="login_title clearfix">
			<h1>用户登录</h1>
			<a href="#">立即注册</a>
		</div>
		<div class="form_input">
			<form id="login_form" onsubmit="return false">
				<input type="text" name="username" class="name_input" placeholder="请输入用户名">
				<div class="user_error">输入错误</div>
				<input type="password" name="password" class="pass_input" placeholder="请输入密码">
				<div class="pwd_error">输入错误</div>
				<div class="more_input clearfix">
					<input type="checkbox" name="">
					<label>记住用户名</label>
					<a href="#">忘记密码</a>
				</div>
				<input type="submit" onclick="submitForm()" name="" value="登录" class="input_submit">
			</form>
		</div>
	</div>


	<script src="${path}/static/lib/jquery-1.11.3.js"></script>
	<script src="${path}/static/lib/mylayer.js"></script>
	<script src="${path}/static/lib/util.js"></script>
	<script src="${path}/static/lib/layui/layui.js"></script>
	
	<script type="text/javascript">
		layui.use(['layer'], function(){
			  var layer = layui.layer;
		});
	
		function insertProductToCart() {
			// session是一个域对象，${user}能取出保存到session中的用户登录信息
			// User user = (User)session.getAttribute("user");
			var user = "${user}";
			if (user == "") { // 这个用户没有登录，弹出登录框
				layer.open({
					type: 1,
					title: "登录",
					offset: "50px",
					area: ["450px", "450px"],
					content: $("#loginForm")
				});
			} else {// 这个用户已经登录，将商品插入购物车，成功后跳转到购物车界面
				$.ajax({
					url: "${path}/cart/insert.shtml",
					data: {"productId":"${product.id}", "num": $("#num").val()},
					tyep: "post",
					dataType: "json",
					success: function(jsonObj) {
						if(jsonObj.code == util.SUCCESS) {
							mylayer.successMsgUrl(jsonObj.msg, "${path}/cart/getCartListPage.shtml");
						} else {
							mylayer.errorMsg(jsonObj.msg);
						}
					}
				});
			}
		}
		
		function submitForm() {
			
			$.ajax({
				url: "${path}/user/login.shtml",
				data: $("#login_form").serialize(),
				type: "post",
				dataType: "json",
				success: function(jsonObj) {
					if (jsonObj.code == util.SUCCESS) {
						mylayer.successMsg(jsonObj.msg);
						//当你在iframe页面关闭自身时
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						/* setTimeout(function(){
							parent.layer.close(index); //再执行关闭 
							// 刷新父页面
							window.parent.location.reload();
						},1000); */
						
						$.ajax({
							url: "${path}/cart/insert.shtml",
							data: {"productId":"${product.id}", "num": $("#num").val()},
							tyep: "post",
							dataType: "json",
							success: function(jsonObj) {
								if(jsonObj.code == util.SUCCESS) {
									mylayer.successMsgUrl(jsonObj.msg, "${path}/cart/getCartListPage.shtml");
								} else {
									mylayer.errorMsg(jsonObj.msg);
								}
								
								//当你在iframe页面关闭自身时
								/* var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭 
								// 刷新父页面
								window.parent.location.reload(); */
							}
						});
					} else {
						mylayer.errorMsg(jsonObj.msg);
					}
				}
			});
		}
	</script>
	
</body>
</html>